<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //求 n 个数字的和
    let getSum = x => {
        if (x == 1) {
            return 1;
        }
        return x + getSum(x - 1)
    }

    let x = getSum(5);
    console.log(x)

    //求个位数字的和 
    //23 >>> 2+3 ; 123 >>> 1+2+3 ;
    let getEverySum = x => {
        if (x < 10) {
            return x;
        }
        return x % 10 + getEverySum(parseInt(x / 10))
    }

    let result = getEverySum(6)
    console.log(result)
</script>

</html>